<template>
  <div class="page-full VUE_DOUYIN">
    <van-nav-bar
      title="巽风脚本选择"
      left-text="返回"
      left-arrow
      @click-left="$router.go(-1)"
    ></van-nav-bar>
    <div class="content mt10">
      <van-form>
        <van-cell-group inset>
          <van-divider
            class="mt10"
            :style="{ color: '#1989fa', borderColor: '#1989fa', padding: '0 16px' }"
          >
            当前分辨率: {{ store.count }}
          </van-divider>
          <!-- <van-field name="radio" label="是否双开">
            <template #input>
              <van-radio-group v-model="model.doSecondApp" direction="horizontal">
                <van-radio :name="1">是</van-radio>
                <van-radio :name="0">否</van-radio>
              </van-radio-group>
            </template>
          </van-field> -->
          <van-field name="radio" label="是否做生产线">
            <template #input>
              <van-radio-group v-model="model.doShengchanxian" direction="horizontal">
                <van-radio :name="1">做</van-radio>
                <van-radio :name="0">不做</van-radio>
              </van-radio-group>
            </template>
          </van-field>
          <van-field name="radio" label="自动上架手札">
            <template #input>
              <van-radio-group v-model="model.autoUp" direction="horizontal">
                <van-radio :name="1">上架</van-radio>
                <van-radio :name="0">不上架</van-radio>
              </van-radio-group>
            </template>
          </van-field>
          <van-field
            v-model="model.price"
            name="price"
            label="扫货价格"
            type="number"
            placeholder="输入价格"
          >
          </van-field>
          <van-field name="taskList" label="需要做的任务">
            <template #input>
              <van-checkbox-group v-model="model.taskList" direction="horizontal">
                <van-checkbox name="1" shape="square">滴滴答</van-checkbox>
                <van-checkbox name="2" shape="square">滴答答</van-checkbox>
                <van-checkbox name="3" shape="square">节气问答</van-checkbox>
                <van-checkbox name="4" shape="square">采集高粱</van-checkbox>
                <van-checkbox name="5" shape="square">采集小麦</van-checkbox>
                <van-checkbox name="6" shape="square">功法寻宝</van-checkbox>
                <van-checkbox name="7" shape="square">节气寻宝</van-checkbox>
                <van-checkbox name="8" shape="square">割稻草</van-checkbox>
                <van-checkbox name="9" shape="square">洁净厂区</van-checkbox>
                <van-checkbox name="10" shape="square">走街串巷</van-checkbox>
                <van-checkbox name="11" shape="square">自动跳舞</van-checkbox>
                <van-checkbox name="12" shape="square">知识问答</van-checkbox>
              </van-checkbox-group>
            </template>
          </van-field>
        </van-cell-group>
        <div style="margin: 16px">
          <van-button round block type="primary" @click="startNow">启动</van-button>
          <van-button class="mt10" round block type="danger" @click="stop">停止</van-button>
          <div class="mt10 c6 fz14"></div>
          双开应用默认全做
          <div>任务结束自动上架手札, 酿酒竞赛时方可启动, 否则有BUG</div>
        </div>
        <div style="margin: 16px">
          <van-button round block type="success" @click="startJishi">扫花</van-button>
          <van-button class="mt10" round block type="success" @click="startCZ">陈总特供</van-button>
          <van-button class="mt10" round block type="success" @click="startGG">gg</van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>
<script>
import store from '@/store'
export default {
  data() {
    return {
      store,
      isFirst: true,
      model: {
        max: 100,
        test: [],
        doSecondApp: 0,
        doShengchanxian: 1,
        taskList: [],
        price: 3,
        autoUp: 0,
        ...JSON.parse(localStorage.VUE_XUNFENG || '{}')
      }
    }
  },
  mounted() {
    this.isFirst = true
    console.log('localStorage.VUE_XUNFENG', localStorage.VUE_XUNFENG)
  },
  unmounted() {
    console.log('保存页面上的数据')
    localStorage.VUE_XUNFENG = JSON.stringify(this.model)
  },
  methods: {
    startJishi() {
      auto.invoke(
        'runRobot',
        [
          {
            robot: require('@/auto/robot/robot.jishi'),
            isFirst: this.isFirst,
            model: this.model
          }
        ],
        () => {
          // log('ajFun1 回调:', typeof r, r)
        }
      )
      this.isFirst = false
    },
    startCZ() {
      auto.invoke(
        'runRobot',
        [
          {
            robot: require('@/auto/robot/robot.cz'),
            isFirst: this.isFirst,
            model: this.model
          }
        ],
        () => {
          // log('ajFun1 回调:', typeof r, r)
        }
      )
      this.isFirst = false
    },
    startNow() {
      auto.invoke(
        'runRobotNow',
        [
          {
            robot: require('@/auto/robot/robot.xf'),
            points: require(`@/auto/xunfeng/${store.count}`),
            model: this.model,
            isFirst: this.isFirst
          }
        ],
        () => {
          // log('ajFun1 回调:', typeof r, r)
        }
      )
      this.isFirst = false
    },
    startGG() {
      auto.invoke(
        'runRobot',
        [
          {
            robot: require('@/auto/robot/robot.gg'),
            isFirst: this.isFirst,
            model: this.model
          }
        ],
        () => {
          // log('ajFun1 回调:', typeof r, r)
        }
      )
      this.isFirst = false
    },
    stop() {
      auto.invoke('robotStop', [], () => {})
    }
  }
}
</script>
<style lang="stylus" scoped></style>
